package com.qf.rbac2202.sys.controller;

import com.qf.rbac2202.sys.entity.SysRole;
import com.qf.rbac2202.sys.service.ISysRoleService;
import com.qf.rbac2202.utils.PageVo;
import com.qf.rbac2202.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author dong_
 * @since 2022-10-28
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {

    @Autowired
    ISysRoleService sysRoleService;

    @GetMapping("/list")
    public R list(@RequestParam Map<String,String> parmas){

        PageVo<SysRole> pageVo =  sysRoleService.queryByPage(parmas);

        return R.ok().put("page", pageVo);
    }

    @PostMapping("/save")
    public R save(@RequestBody SysRole sysRole){

        sysRoleService.saveRole(sysRole);

        return R.ok();

    }

    @GetMapping("/info/{roleId}")
    public R info(@PathVariable("roleId") Long roleId){

        SysRole role  = sysRoleService.getRoleById(roleId);

        return R.ok().put("role", role);
    }


    @PostMapping("/update")
    public R update(@RequestBody SysRole sysRole){

        sysRoleService.updateRole(sysRole);

        return R.ok();

    }

}
